Skip to content

Tests: Improve Windows compatibility#200

Merged
swissspidy merged 10 commits intomainfrom
fix/windows-tests
Mar 29, 2026
Merged

Tests: Improve Windows compatibility#200
swissspidy merged 10 commits intomainfrom
fix/windows-tests

Conversation

@swissspidy
Copy link
Copy Markdown
Member

No description provided.

@github-actions
Copy link
Copy Markdown
Contributor

Hello! 👋

Thanks for opening this pull request! Please check out our contributing guidelines. We appreciate you taking the initiative to contribute to this project.

Contributing isn't limited to just code. We encourage you to contribute in the way that best fits your abilities, by writing tutorials, giving a demo at your local meetup, helping other users with their support questions, or revising our documentation.

Here are some useful Composer commands to get you started:

  • composer install: Install dependencies.
  • composer test: Run the full test suite.
  • composer phpcs: Check for code style violations.
  • composer phpcbf: Automatically fix code style violations.
  • composer phpunit: Run unit tests.
  • composer behat: Run behavior-driven tests.

To run a single Behat test, you can use the following command:

# Run all tests in a single file
composer behat features/some-feature.feature

# Run only a specific scenario (where 123 is the line number of the "Scenario:" title)
composer behat features/some-feature.feature:123

You can find a list of all available Behat steps in our handbook.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 29, 2026

Codecov Report

❌ Patch coverage is 12.50000% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
lib/cli/Shell.php 12.50% 7 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates Shell.php to prioritize the COLUMNS environment variable for terminal width detection and includes test updates to handle Windows-specific behavior and line-ending normalization. Feedback highlights a bug in the environment variable restoration logic within Test_Shell.php, where setting WP_CLI_TEST_IS_WINDOWS to an empty string on Windows incorrectly causes is_windows() to return false, potentially breaking subsequent tests.

Comment on lines +52 to +60
if ( false === $env_is_windows ) {
if ( strtoupper( substr( PHP_OS, 0, 3 ) ) === 'WIN' ) {
putenv( 'WP_CLI_TEST_IS_WINDOWS=' );
} else {
putenv( 'WP_CLI_TEST_IS_WINDOWS' );
}
} else {
putenv( "WP_CLI_TEST_IS_WINDOWS=$env_is_windows" );
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This change to restore the WP_CLI_TEST_IS_WINDOWS environment variable introduces a problem for tests running on Windows.

On Windows, putenv('WP_CLI_TEST_IS_WINDOWS=') sets the variable to an empty string. Consequently, is_windows() will return false because (bool)'' is false. This breaks test isolation, as subsequent tests will incorrectly detect the OS as non-Windows.

The underlying issue is in is_windows(), which doesn't differentiate an unset variable from one set to an empty string. The ideal fix is to make is_windows() more robust, for instance:

if (false !== $test_is_windows && '' !== $test_is_windows) {
    return (bool) $test_is_windows;
}

Since modifying is_windows() might be out of scope for this file, this restoration logic needs to be re-evaluated to avoid breaking other tests.

@swissspidy swissspidy added this to the 0.12.9 milestone Mar 29, 2026
@swissspidy swissspidy marked this pull request as ready for review March 29, 2026 11:01
@swissspidy swissspidy requested a review from a team as a code owner March 29, 2026 11:01
Copilot AI review requested due to automatic review settings March 29, 2026 11:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates CLI-related tests and shell utilities to behave consistently on Windows, addressing environment-variable handling and line-ending differences.

Changes:

  • Normalize CRLF vs LF when asserting ASCII table output written to a temp file.
  • Adjust table rendering tests to account for Windows behavior when evaluating wrapped multibyte output.
  • Improve Shell::columns() and Shell::is_windows() behavior around COLUMNS and WP_CLI_TEST_IS_WINDOWS.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
tests/Test_Table_Ascii.php Normalizes line endings before comparing expected vs actual output.
tests/Test_Table.php Adds Windows-specific expectations for multibyte-width wrapping assertions.
tests/Test_Shell.php Restores WP_CLI_TEST_IS_WINDOWS in a Windows-safe way (empty vs unset).
lib/cli/Shell.php Prefers COLUMNS before exec()-based detection; treats empty test override as “not set”.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@swissspidy swissspidy merged commit c3d2513 into main Mar 29, 2026
22 of 23 checks passed
@swissspidy swissspidy deleted the fix/windows-tests branch March 29, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants